package com.jlf.controller.engine.entity.field;

import com.jlf.core.constant.Constants;
import com.jlf.core.engine.constant.SchemaConstant;
import com.jlf.core.engine.domain.SchemaFieldDO;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;



/**
 * 模型领域字段的输入
 *
 * @author wujr
 * 2023/7/8
 * @version 1.0
 * 【变更历史】
 * [wujr 2023/7/8 1.0 新增]
 */
@Getter
@Setter
public class SchemaFieldInput {
    /**
     * 生成的模型的字段数据类型 {@link SchemaConstant.Java.Type}
     */
    @NotNull(message = "类数据类型不能为空")
    @Min(value = SchemaConstant.Java.Type.MIN, message = "不支持的数据类型")
    @Max(value = SchemaConstant.Java.Type.MAX, message = "不支持的数据类型")
    private Integer classDataType;
    @NotBlank(message = "类字段编码不能为空")
    private String classFieldCode;
    @NotBlank(message = "显示名称不能为空")
    private String displayName;
    private String jdbcFieldCode;
    /**
     * 数据库字段类型 {@link SchemaConstant.Jdbc.Type}
     */
    @NotNull(message = "数据库字段类型不能为空")
    @Min(value = SchemaConstant.Jdbc.Type.MIN, message = "不支持的数据库字段数据类型")
    @Max(value = SchemaConstant.Jdbc.Type.MAX, message = "不支持的数据库字段数据类型")
    private Integer jdbcFieldType;
    private Integer jdbcFieldLength;
    private Boolean jdbcNullable = Boolean.FALSE;
    private String defaultValue;
    @NotNull(message = "排序不能为空")
    private Integer priority;
    @Min(value = 0, message = "不支持的模型字段状态")
    @Max(value = 1, message = "不支持的模型字段状态")
    private Integer status = Constants.Status.enabled;

    public SchemaFieldDO to(){
        SchemaFieldDO record = new SchemaFieldDO();
        record.setClassDataType(classDataType);
        record.setClassFieldCode(classFieldCode);
        record.setDisplayName(displayName);
        record.setJdbcFieldCode(jdbcFieldCode);
        record.setJdbcFieldLength(jdbcFieldLength);
        record.setJdbcFieldType(jdbcFieldType);
        record.setJdbcNullable(jdbcNullable);
        record.setDefaultValue(defaultValue);
        record.setPriority(priority);
        record.setStatus(status);

        return record;
    }
}
